package com.alex.dao.impl;

import com.alex.dao.BookShopDao;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class BookShopDaoImpl implements BookShopDao {

    @Autowired
    private SessionFactory sessionFactory;

    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }

    @Override
    public int findBookPriceByIsbn(String isbn) {
        String hql = "select b.price from Book b where b.isbn=?";
        Query query = getSession().createQuery(hql).setString(0, isbn);
        return (Integer) query.uniqueResult();
    }

    @Override
    public int getBookStock(String isbn) {
        return 0;
    }

    @Override
    public int getUserAccount(String username) {
        return 0;
    }

    @Override
    public void updateBookStock(String isbn) {

    }

    @Override
    public void updateUserAccount(String username, int price) {

    }
}
